<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
	<s:head theme="ajax"/>	
	<style>
		body, input{
			font-family: Calibri, Arial;
		}
		table#contact {
			border-collapse: collapse;
			width:550px;
		}
		th {
			height: 40px;
			background-color: #ffee55;
		}
	</style>
	<title>Prodotto Manager - Project Live!</title>
</head>
<body>

	<div id="insDiv" class="insDiv">
		<h1> 
			<img class="insDivImg insDivImgOpen" src="images/arr-open.png"/> 
			<span>Inserimento Prodotto</span>
		</h1>
	</div>	
	<s:actionerror/>

	<div id="insBox" class="insBox">
		<s:form action="addProdotto" method="post" theme="simple">
			<s:hidden name="id" value="%{id}"/>
			<table>
				<tr>
					<td><s:label value="Nome:"/></td>
					<td><s:textfield name="prodotto.nome"/></td>
					<td><s:label value="Descrizione:"/></td>
					<td><s:textfield name="prodotto.descrizione"/></td>
					<td><s:label value="Marca:"/></td>
					<td><s:textfield name="prodotto.marca"/></td>	
					<td><s:label value="Modello:"/></td>
					<td><s:textfield name="prodotto.modello"/></td>
				</tr>
				<tr>
					<td><s:label value="Costa Acquisto:"/></td>
					<td><s:textfield name="prodotto.costoacquisto"/></td>
					<td><s:label value="Costo Noleggio:"/></td>
					<td><s:textfield name="prodotto.costonoleggio"/></td>
					<td><s:label value="Data Acquisto:"/></td>
					<td><s:datetimepicker name="prodotto.dataacquisto" displayFormat="dd/MM/yyyy" required="true" />
					</td>
					<td></td>
				</tr>
				<tr>
					<td><s:label value="Quantita':"/></td>
					<td><s:textfield name="prodotto.qty"/></td>	
					<td><s:label value="Categoria:"/></td>
					<td><s:select list="categorie" listKey="id" listValue="nome" name="prodotto.idcategoria" 
							headerKey="-1" headerValue=" --- " onchange="this.form.submit()"/></td>
					<td><s:label value="SottoCategoria:"/></td>
					<td><s:select list="sottoCategorie" listKey="id" listValue="nome" name="prodotto.idsottocategoria"
							headerKey="-1" headerValue=" --- " /></td>
					<td></td>
					<td></td>
				</tr>			
			</table>
			<s:submit value="Salva Prodotto" align="center"/>
		</s:form>
	</div>	

	</br></br>
	<div class="subHeader_Tab">
		<h2>Prodotti</h2>
	</div>	
	<table id="rounded-corner">
		<tr>
			<th class="width5 textCenter"></th>
			<th class="width5 textCenter">Qty</th>
			<th class="textLeft">Nome</th>
			<th class="textLeft">Descrizione</th>
			<th class="textLeft">Modello</th>
			<th class="textLeft">Marca</th>
			<th class="textLeft">Costo Acquisto</th>
			<th class="textLeft">Costo Noleggio</th>
			<th class="textLeft">Data Acquisto</th>
			<th class="textLeft">Categoria</th>
			<th class="width10 textCenter">Modifica</th>
			<th class="width10 textCenter">Elimina</th>
		</tr>
		<s:iterator value="prodotti">
		<tr>
			<td class="textCenter">
				<s:if test="%{qty<5}">
					<img src="images/red.png" height="16" width="16"/>
				</s:if>
				<s:else>
					<img src="images/green.png" height="16" width="16"/>
				</s:else>
			</td>
			<td class="textCenter"><s:property value="qty"/></td>
			<td class="textLeft"><s:property value="Nome"/></td>
			<td class="textLeft"><s:property value="Descrizione"/></td>
			<td class="textLeft"><s:property value="Modello"/></td>
			<td class="textLeft"><s:property value="Marca"/></td>			
			<td class="textLeft"><s:property value="costoacquisto"/> Euro</td>
			<td class="textLeft"><s:property value="costonoleggio"/> Euro</td>	
			<td class="textLeft"><s:property value="dataacquisto"/></td>	
			<td class="textLeft"><s:property value="nomecategoria"/></td>				
			<td>
				<s:form theme="simple">			        
			        <s:submit action="editProdotto" value="Modifica"/>
			        <s:hidden name="id" value="%{id}"/>
			    </s:form>
			</td>
			<td>
				<s:form theme="simple">			        
			        <s:submit action="deleteProdotto" value="Elimina" onclick="return confirm('Sei sicuro di voler cancellare l elemento?');"/>
			        <s:hidden name="id" value="%{id}"/>
			    </s:form>
			</td>
		</tr>	
		</s:iterator>
	</table>
</body>
</html>